/*******************************************************************************
 * Level Master 2000
 * Copyright (C) 2010 Christian Herzog
 * For more information see http://code.google.com/p/levelmaster2000/
 *
 * This file is licensed under the terms of the MIT license, see
 * http://www.opensource.org/licenses/mit-license.php for further information.
 ******************************************************************************/

#ifndef CREATE_ENTITY_COMMAND_H
#define CREATE_ENTITY_COMMAND_H

#include <QUndoCommand>
#include <QStringList>

#include "../EntityExplorer.h"
#include "../Entity.h"
#include "../LevelMaster2000.h"

class CreateObjectCommand : public QUndoCommand
{
public:
    CreateObjectCommand( EntityExplorer* entityExplorer,
                         QString name,
                         QString group,
                         QUndoCommand *parent = 0 )
                             : QUndoCommand( parent ),
                             entityExplorer( entityExplorer ),
                             name( name ),
                             group( group )
    {
    }

    void undo()
    {
        setText( "Create Entity \"" + name + "\"" );
        LevelMaster2000::DISALLOW_NEW_COMMAND++;
        entityExplorer->deleteEntity( name );
        LevelMaster2000::DISALLOW_NEW_COMMAND--;
    }

    void redo()
    {
        setText( "Create Entity \"" + name + "\"" );

        if( !LevelMaster2000::DISALLOW_NEW_COMMAND )
        {
            LevelMaster2000::DISALLOW_NEW_COMMAND++;
            entityExplorer->createEntity( name, group );
            LevelMaster2000::DISALLOW_NEW_COMMAND--;
        }
    }

private:
    EntityExplorer *entityExplorer;
    QString name;
    QString group;
};

#endif
